#include "xmltrajectorywriter.h"

using namespace mlgesture;
using namespace std;

XmlTrajectoryWriter::XmlTrajectoryWriter(vector<Trajectory> *trajectories) :
	trajectories_(trajectories) {
	xml_.setAutoFormatting(true);
}

void XmlTrajectoryWriter::write(QIODevice *device) {
	xml_.setDevice(device);

	xml_.writeStartDocument();
	xml_.writeStartElement("trajectory_set");
	xml_.writeAttribute("version", "1.0");

	for(size_t i=0; i<trajectories_->size(); i++) {
		xml_.writeStartElement("trajectory");
		xml_.writeAttribute("type", QString::fromStdString(trajectories_->at(i).type_));
		for(size_t j=0; j<trajectories_->at(i).data_.size(); j++) {
			xml_.writeTextElement("direction", QString::number(trajectories_->at(i).data_[j]));
		}
		xml_.writeEndElement();
	}
	xml_.writeEndDocument();
}

